//
//  ViewController.swift
//  MichaelToy
//
//  Created by MichaelSun on 2017/11/1.
//  Copyright © 2017年 MichaelSun. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var rView: cellView!
    @IBOutlet weak var gView: cellView!
    @IBOutlet weak var bView: cellView!
    
    @IBAction func onPressButton(_ sender: Any) {
        let button = sender as! UIButton
        let color = button.backgroundColor
        colorAnimate(toColor: color!)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.view.backgroundColor = UIColor.green
        let rgb = MSColorAnimate.getRGB(withColor: self.view.backgroundColor!)
        self.rView.value = Float(rgb.r)
        self.gView.value = Float(rgb.g)
        self.bView.value = Float(rgb.b)
        
        
       
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        let pet = MSPet.initMSPet(moveProperty: MSPetMoveProperty(speedH: 3, speedV: 3))
       pet.show()
        pet.move()
        
        
    }
    func colorAnimate(toColor color: UIColor){
        _ = MSColorAnimate(withDuration: 1, fromColor: view.backgroundColor!, toColor: color, animation: { (color) in
            let rgb = MSColorAnimate.getRGB(withColor: color)
            self.rView.value = Float(rgb.r)
            self.gView.value = Float(rgb.g)
            self.bView.value = Float(rgb.b)
            self.view.backgroundColor = color
        }) { (isSuccess) in
            print(Date())
        }
        
        
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

